package com.example.xianji.activity;

import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.Request.Method;
import com.android.volley.Response.Listener;
import com.android.volley.toolbox.JsonObjectRequest;
import com.example.xianji.Contant;
import com.example.xianji.XJApplication;
import com.example.xianji.R;
import com.example.xianji.bean.YiJi_Class;
import com.example.xianji.constant.Constant;
import com.example.xianji.utils.sp.PreferenceEngine;
import com.example.xianji.widgets.CustomProgressDialog;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.drawable.BitmapDrawable;
import android.text.ClipboardManager;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

public class Main_geren_send_fuwuActivity extends Activity implements OnClickListener {
    private ImageView send_fuwu_back;
    private ClipboardManager clipboard;
    private InputMethodManager manager;
    private PopupWindow show_popupWindow;
    private ListView show_listview;
    private LinearLayout layout;
    private Button send_fuwu_yiji, button_erji_fuwu_fenlei, button_sanji_fenlei, geren_fuwu_send, button_province, button_city, button_district;
    //    private SharedPreferences sp;
//    private Editor ed;
    private MyAdapter mMyAdapter;
    private ArrayList<YiJi_Class> list = new ArrayList<YiJi_Class>();
    private Boolean yiji_flag = false, erji_flag = false, sanji_flag = false, province_flag = false, city_flag = false, district_flag = false;
    private int yiji_id, erji_id, sanji_id, province_id, city_id, district_id;
    private EditText editText_fuwu_title, editText_fuwu_details;
    private int yiji_fenlei_indext = 1, erji_fenlei_indext = 1, province_indext = 1, city_indext = 1;
    private LinearLayout layout_geren_send_fuwu;
    private CustomProgressDialog mCustomProgressDialog;
    private Handler handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == 1) {
                show_listview.setAdapter(mMyAdapter);
                if (mCustomProgressDialog != null) {
                    mCustomProgressDialog.dismiss();
                    mCustomProgressDialog = null;
                }
            }
            if (msg.what == 2) {
                if (mCustomProgressDialog != null) {
                    mCustomProgressDialog.dismiss();
                    mCustomProgressDialog = null;
                }
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
        setContentView(R.layout.activity_main_geren_send_fuwu);
        send_fuwu_back = (ImageView) findViewById(R.id.geren_send_fuwu_back);
        send_fuwu_yiji = (Button) findViewById(R.id.send_fuwu_yiji);
        button_erji_fuwu_fenlei = (Button) findViewById(R.id.button_erji_fuwu_fenlei);
        button_sanji_fenlei = (Button) findViewById(R.id.button_sanji_fenlei);
        geren_fuwu_send = (Button) findViewById(R.id.geren_fuwu_send);
        editText_fuwu_title = (EditText) findViewById(R.id.editText_fuwu_title);
        editText_fuwu_details = (EditText) findViewById(R.id.editText_fuwu_details);
        button_province = (Button) findViewById(R.id.button_province);
        button_city = (Button) findViewById(R.id.button_city);
        button_district = (Button) findViewById(R.id.button_district);
        layout_geren_send_fuwu = (LinearLayout) findViewById(R.id.linear_geren_send_fuwu);
//        sp = getSharedPreferences("text", MODE_PRIVATE);
//        ed = sp.edit();

        mMyAdapter = new MyAdapter();
        clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        getWindow().setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        hideKeyboard();

        send_fuwu_back.setOnClickListener(this);
        send_fuwu_yiji.setOnClickListener(this);
        button_sanji_fenlei.setOnClickListener(this);
        button_province.setOnClickListener(this);
        button_city.setOnClickListener(this);
        button_district.setOnClickListener(this);
        layout_geren_send_fuwu.setOnClickListener(this);
        geren_fuwu_send.setOnClickListener(this);
        button_erji_fuwu_fenlei.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.geren_send_fuwu_back) {
            Main_geren_send_fuwuActivity.this.finish();
        } else if (v.getId() == R.id.send_fuwu_yiji) {
            Photo_show();
            show_popupWindow.showAtLocation(findViewById(R.id.geren_send_fuwu), Gravity.BOTTOM, 0, 0);

            mCustomProgressDialog = CustomProgressDialog.createDialog(getApplicationContext());
            mCustomProgressDialog.setCanceledOnTouchOutside(false);
            mCustomProgressDialog.show();
            get_yji_fuwu_fenlei();
            show_listview.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1,
                                        int arg2, long arg3) {
                    send_fuwu_yiji.setText(list.get(arg2).getName());
                    send_fuwu_yiji.setTextColor(getResources().getColor(R.color.black3F));
                    yiji_flag = true;
                    yiji_fenlei_indext++;
                    yiji_id = list.get(arg2).getId();
                    if (yiji_fenlei_indext > 2) {
                        button_erji_fuwu_fenlei.setText("请选择二级分类");
                        button_erji_fuwu_fenlei.setTextColor(getResources().getColor(R.color.gray98));
                        button_sanji_fenlei.setText("请选择三级分类");
                        button_sanji_fenlei.setTextColor(getResources().getColor(R.color.gray98));
                        erji_flag = false;
                        sanji_flag = false;
                    }
                    show_popupWindow.dismiss();
                    show_popupWindow = null;
                }
            });


        } else if (v.getId() == R.id.button_erji_fuwu_fenlei) {
            if (yiji_flag) {
                Photo_show();
                show_popupWindow.showAtLocation(findViewById(R.id.geren_send_fuwu), Gravity.BOTTOM, 0, 0);
                mCustomProgressDialog = CustomProgressDialog.createDialog(this);
                mCustomProgressDialog.setCanceledOnTouchOutside(false);
                mCustomProgressDialog.show();
                get_erji_fuwu_fenlei();
                show_listview.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> arg0, View arg1,
                                            int arg2, long arg3) {
                        button_erji_fuwu_fenlei.setText(list.get(arg2).getName());
                        button_erji_fuwu_fenlei.setTextColor(getResources().getColor(R.color.black3F));
                        erji_id = list.get(arg2).getId();
                        erji_flag = true;
                        erji_fenlei_indext++;
                        if (erji_fenlei_indext > 2) {
                            button_sanji_fenlei.setText("请选择三级分类");
                            button_sanji_fenlei.setTextColor(getResources().getColor(R.color.gray98));
                            sanji_flag = false;
                        }
                        show_popupWindow.dismiss();
                        show_popupWindow = null;
                    }
                });
            } else {
                Toast.makeText(Main_geren_send_fuwuActivity.this, "请先选择一级分类", Toast.LENGTH_SHORT).show();
            }
        } else if (v.getId() == R.id.button_sanji_fenlei) {

            if (erji_flag) {
                if (erji_id == 0) {
                    Toast.makeText(Main_geren_send_fuwuActivity.this, "没有三级分类了哦", Toast.LENGTH_SHORT).show();
                } else {
                    Photo_show();
                    show_popupWindow.showAtLocation(findViewById(R.id.geren_send_fuwu), Gravity.BOTTOM, 0, 0);

                    mCustomProgressDialog = CustomProgressDialog.createDialog(this);
                    mCustomProgressDialog.setCanceledOnTouchOutside(false);
                    mCustomProgressDialog.show();
                    get_sanji_fuwu_fenlei();
                    show_listview.setOnItemClickListener(new OnItemClickListener() {

                        @Override
                        public void onItemClick(AdapterView<?> arg0, View arg1,
                                                int arg2, long arg3) {
                            button_sanji_fenlei.setText(list.get(arg2).getName());
                            button_sanji_fenlei.setTextColor(getResources().getColor(R.color.black3F));
                            sanji_id = list.get(arg2).getId();

                            sanji_flag = true;
                            show_popupWindow.dismiss();
                            show_popupWindow = null;
                        }
                    });
                }
            } else {
                Toast.makeText(Main_geren_send_fuwuActivity.this, "请先选择二级分类", Toast.LENGTH_SHORT).show();
            }
        } else if (v.getId() == R.id.geren_fuwu_send) {
            if (editText_fuwu_title.getText().toString().length() > 0) {
                if (editText_fuwu_details.getText().toString().length() > 0) {

                    if (yiji_flag) {
                        if (erji_flag) {
                            if (sanji_flag) {
                                if (province_flag) {
                                    if (city_flag) {
                                        if (district_flag) {
                                            mCustomProgressDialog = CustomProgressDialog.createDialog(this);
                                            mCustomProgressDialog.setCanceledOnTouchOutside(false);
                                            mCustomProgressDialog.show();
                                            get_send_fuwu();
                                        } else {
                                            Toast.makeText(Main_geren_send_fuwuActivity.this, "请选择地区", Toast.LENGTH_SHORT).show();
                                        }
                                    } else {
                                        Toast.makeText(Main_geren_send_fuwuActivity.this, "请选择城市", Toast.LENGTH_SHORT).show();
                                    }
                                } else {
                                    Toast.makeText(Main_geren_send_fuwuActivity.this, "请选择省份", Toast.LENGTH_SHORT).show();
                                }
                            } else {
                                Toast.makeText(Main_geren_send_fuwuActivity.this, "请选择三级分类", Toast.LENGTH_SHORT).show();
                            }
                        } else {
                            Toast.makeText(Main_geren_send_fuwuActivity.this, "请选择二级分类", Toast.LENGTH_SHORT).show();
                        }
                    } else {
                        Toast.makeText(Main_geren_send_fuwuActivity.this, "请选择一级分类", Toast.LENGTH_SHORT).show();
                    }
                } else {
                    Toast.makeText(Main_geren_send_fuwuActivity.this, "请填写服务内容", Toast.LENGTH_SHORT).show();
                }
            } else {
                Toast.makeText(Main_geren_send_fuwuActivity.this, "请填写服务名称", Toast.LENGTH_SHORT).show();
            }
        } else if (v.getId() == R.id.button_province) {
            Photo_show();
            show_popupWindow.showAtLocation(findViewById(R.id.geren_send_fuwu), Gravity.BOTTOM, 0, 0);
            mCustomProgressDialog = CustomProgressDialog.createDialog(this);
            mCustomProgressDialog.setCanceledOnTouchOutside(false);
            mCustomProgressDialog.show();
            get_province();
            show_listview.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1,
                                        int arg2, long arg3) {
                    button_province.setText(list.get(arg2).getName());
                    button_province.setTextColor(getResources().getColor(R.color.black3F));
                    province_id = list.get(arg2).getId();
                    province_flag = true;
                    province_indext++;
                    if (province_indext > 2) {
                        button_city.setText("请选择城市");
                        button_city.setTextColor(getResources().getColor(R.color.gray98));
                        button_district.setText("请选择区");
                        button_district.setTextColor(getResources().getColor(R.color.gray98));
                        city_flag = false;
                        district_flag = false;
                    }
                    show_popupWindow.dismiss();
                    show_popupWindow = null;
                }
            });

        } else if (v.getId() == R.id.button_city) {
            if (province_flag) {
                mCustomProgressDialog = CustomProgressDialog.createDialog(this);
                mCustomProgressDialog.setCanceledOnTouchOutside(false);
                mCustomProgressDialog.show();
                Photo_show();
                show_popupWindow.showAtLocation(findViewById(R.id.geren_send_fuwu), Gravity.BOTTOM, 0, 0);
                if (button_province.getText().toString().equals("北京") || button_province.getText().toString().equals("上海") || button_province.getText().toString().equals("天津") ||
                        button_province.getText().toString().equals("香港") || button_province.getText().toString().equals("台湾")
                        ) {
                    get_teshu_province();
                } else {
                    get_city();
                }

                show_listview.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> arg0, View arg1,
                                            int arg2, long arg3) {
                        button_city.setText(list.get(arg2).getName());
                        button_city.setTextColor(getResources().getColor(R.color.black3F));
                        city_id = list.get(arg2).getId();
                        city_flag = true;
                        city_indext++;
                        if (city_indext > 2) {
                            button_district.setText("请选择区");
                            button_district.setTextColor(getResources().getColor(R.color.gray98));
                            district_flag = false;
                        }
                        show_popupWindow.dismiss();
                        show_popupWindow = null;
                    }
                });
            } else {
                Toast.makeText(Main_geren_send_fuwuActivity.this, "请先选择省份", Toast.LENGTH_SHORT).show();
            }
        } else if (v.getId() == R.id.button_district) {
            if (city_flag) {
                Photo_show();
                show_popupWindow.showAtLocation(findViewById(R.id.geren_send_fuwu), Gravity.BOTTOM, 0, 0);
                mCustomProgressDialog = CustomProgressDialog.createDialog(this);
                mCustomProgressDialog.setCanceledOnTouchOutside(false);
                mCustomProgressDialog.show();
                get_district();

                show_listview.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> arg0, View arg1,
                                            int arg2, long arg3) {
                        button_district.setText(list.get(arg2).getName());
                        button_district.setTextColor(getResources().getColor(R.color.black3F));
                        district_id = list.get(arg2).getId();
                        district_flag = true;
                        show_popupWindow.dismiss();
                        show_popupWindow = null;
                    }
                });
            } else {
                Toast.makeText(Main_geren_send_fuwuActivity.this, "请先选择城市", Toast.LENGTH_SHORT).show();
            }

        } else if (v.getId() == R.id.linear_geren_send_fuwu) {
            if (show_popupWindow != null) {
                show_popupWindow.dismiss();
                show_popupWindow = null;
            }
        }
    }

    /**
     * 隐藏软键盘
     */
    private void hideKeyboard() {
        if (getWindow().getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
            if (getCurrentFocus() != null)
                manager.hideSoftInputFromWindow(getCurrentFocus()
                        .getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }

    public void get_yji_fuwu_fenlei() {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
//        map.put("token", sp.getString("xianji_token", ""));
        map.put("cid", 0);
        JSONObject params = new JSONObject(map);

        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.geren_fuwu_fenlei,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        list.clear();
                        JSONArray array = response.getJSONArray("data");
                        JSONArray array1 = array.getJSONArray(0);
                        for (int i = 0; i < array1.length(); i++) {
                            JSONObject obj = array1.getJSONObject(i);
                            YiJi_Class mYiJi_Class = new YiJi_Class();
                            mYiJi_Class.setId(obj.getInt("id"));
                            mYiJi_Class.setName(obj.getString("name"));
                            list.add(mYiJi_Class);
                        }
                        handler.sendEmptyMessage(1);
                    } else {
                        Toast.makeText(Main_geren_send_fuwuActivity.this, response.getString("msg"), Toast.LENGTH_SHORT).show();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                if (mCustomProgressDialog != null) {
                    mCustomProgressDialog.dismiss();
                    mCustomProgressDialog = null;
                }
                if (show_popupWindow != null) {
                    show_popupWindow.dismiss();
                    show_popupWindow = null;
                }
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(30 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    public void get_erji_fuwu_fenlei() {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
//        map.put("token", sp.getString("xianji_token", ""));
        map.put("cid", yiji_id);
        JSONObject params = new JSONObject(map);
        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.geren_fuwu_fenlei,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        list.clear();
                        JSONArray array = response.getJSONArray("data");
                        JSONArray array1 = array.getJSONArray(0);
                        for (int i = 0; i < array1.length(); i++) {
                            JSONObject obj = array1.getJSONObject(i);
                            YiJi_Class mYiJi_Class = new YiJi_Class();
                            mYiJi_Class.setId(obj.getInt("id"));
                            mYiJi_Class.setName(obj.getString("name"));
                            list.add(mYiJi_Class);
                        }
                        handler.sendEmptyMessage(1);
                    } else {
                        Toast.makeText(Main_geren_send_fuwuActivity.this, response.getString("msg"), Toast.LENGTH_SHORT).show();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                if (mCustomProgressDialog != null) {
                    mCustomProgressDialog.dismiss();
                    mCustomProgressDialog = null;
                }
                if (show_popupWindow != null) {
                    show_popupWindow.dismiss();
                    show_popupWindow = null;

                }
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    public void get_sanji_fuwu_fenlei() {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
//        map.put("token", sp.getString("xianji_token", ""));
        map.put("cid", erji_id);
        JSONObject params = new JSONObject(map);

        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.geren_fuwu_fenlei,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        list.clear();
                        JSONArray array = response.getJSONArray("data");
                        JSONArray array1 = array.getJSONArray(0);
                        for (int i = 0; i < array1.length(); i++) {
                            JSONObject obj = array1.getJSONObject(i);
                            YiJi_Class mYiJi_Class = new YiJi_Class();
                            mYiJi_Class.setId(obj.getInt("id"));
                            mYiJi_Class.setName(obj.getString("name"));
                            list.add(mYiJi_Class);
                        }
                        handler.sendEmptyMessage(1);
                    } else {
                        Toast.makeText(Main_geren_send_fuwuActivity.this, response.getString("msg"), Toast.LENGTH_SHORT).show();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                if (mCustomProgressDialog != null) {
                    mCustomProgressDialog.dismiss();
                    mCustomProgressDialog = null;
                }
                if (show_popupWindow != null) {
                    show_popupWindow.dismiss();
                    show_popupWindow = null;
                }
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    /**
     * 个人发布服务提交
     */
    public void get_send_fuwu() {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
//        map.put("token", sp.getString("xianji_token", ""));
        map.put("title", editText_fuwu_title.getText().toString());
        map.put("details", editText_fuwu_details.getText().toString());
        map.put("parent", yiji_id);
        map.put("category", erji_id);
        map.put("categorytwo", sanji_id);
        map.put("province", province_id);
        map.put("city", city_id);
        map.put("district", district_id);
        JSONObject params = new JSONObject(map);
        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.geren_fuwu_send,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    Toast.makeText(Main_geren_send_fuwuActivity.this, response.getString("msg"), Toast.LENGTH_SHORT).show();
                    if (response.getInt("status") == 1) {
                        handler.sendEmptyMessage(2);
                        Main_geren_send_fuwuActivity.this.finish();
                    } else {
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                if (mCustomProgressDialog != null) {
                    mCustomProgressDialog.dismiss();
                    mCustomProgressDialog = null;
                }
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    /**
     * 省份请求
     */
    public void get_province() {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("pid", 0);
        JSONObject params = new JSONObject(map);

        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.place,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        list.clear();
                        JSONArray array = response.getJSONArray("data");
                        for (int i = 0; i < array.length(); i++) {
                            JSONObject obj = array.getJSONObject(i);
                            YiJi_Class mYiJi_Class = new YiJi_Class();
                            mYiJi_Class.setId(obj.getInt("id"));
                            mYiJi_Class.setName(obj.getString("name"));

                            list.add(mYiJi_Class);
                        }
                        handler.sendEmptyMessage(1);
                    } else {
                        Toast.makeText(Main_geren_send_fuwuActivity.this, response.getString("msg"), Toast.LENGTH_SHORT).show();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                if (mCustomProgressDialog != null) {
                    mCustomProgressDialog.dismiss();
                    mCustomProgressDialog = null;
                }
                if (show_popupWindow != null) {
                    show_popupWindow.dismiss();
                    show_popupWindow = null;
                }
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    /**
     * 省份请求
     */
    public void get_teshu_province() {
        list.clear();
        YiJi_Class mYiJi_Class = new YiJi_Class();
        mYiJi_Class.setId(province_id);
        mYiJi_Class.setName(button_province.getText().toString());
        list.add(mYiJi_Class);
        handler.sendEmptyMessage(1);
    }

    /**
     * 城市请求
     */
    public void get_district() {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("pid", city_id);
        JSONObject params = new JSONObject(map);
        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.place,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        list.clear();
                        JSONArray array = response.getJSONArray("data");
                        for (int i = 0; i < array.length(); i++) {
                            JSONObject obj = array.getJSONObject(i);
                            YiJi_Class mYiJi_Class = new YiJi_Class();
                            mYiJi_Class.setId(obj.getInt("id"));
                            mYiJi_Class.setName(obj.getString("name"));
                            list.add(mYiJi_Class);
                        }
                        handler.sendEmptyMessage(1);
                    } else {
                        Toast.makeText(Main_geren_send_fuwuActivity.this, response.getString("msg"), Toast.LENGTH_SHORT).show();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                if (mCustomProgressDialog != null) {
                    mCustomProgressDialog.dismiss();
                    mCustomProgressDialog = null;
                }
                if (show_popupWindow != null) {
                    show_popupWindow.dismiss();
                    show_popupWindow = null;
                }
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    /**
     * 地区请求
     */
    public void get_city() {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("pid", province_id);
        JSONObject params = new JSONObject(map);

        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.place,
                params, new Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        list.clear();
                        JSONArray array = response.getJSONArray("data");
                        for (int i = 0; i < array.length(); i++) {
                            JSONObject obj = array.getJSONObject(i);
                            YiJi_Class mYiJi_Class = new YiJi_Class();
                            mYiJi_Class.setId(obj.getInt("id"));
                            mYiJi_Class.setName(obj.getString("name"));
                            list.add(mYiJi_Class);
                        }
                        handler.sendEmptyMessage(1);
                    } else {
                        Toast.makeText(Main_geren_send_fuwuActivity.this, response.getString("msg"), Toast.LENGTH_SHORT).show();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                if (mCustomProgressDialog != null) {
                    mCustomProgressDialog.dismiss();
                    mCustomProgressDialog = null;
                }
                if (show_popupWindow != null) {
                    show_popupWindow.dismiss();
                    show_popupWindow = null;
                }
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    private void Photo_show() {
        layout = (LinearLayout) LayoutInflater.from(
                Main_geren_send_fuwuActivity.this).inflate(
                R.layout.information_shoow_photo, null);
        show_listview = (ListView) layout.findViewById(R.id.information_photo_listview);
        show_listview.setCacheColorHint(0);
        show_popupWindow = new PopupWindow(layout, WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.WRAP_CONTENT);
        show_popupWindow.setBackgroundDrawable(new BitmapDrawable());
        show_popupWindow.setHeight(700);
        show_popupWindow.setAnimationStyle(R.style.mypopwindow_anim_style);
        show_popupWindow.update();
        show_popupWindow.setOutsideTouchable(true);
        show_popupWindow.setFocusable(true);
        show_popupWindow.setContentView(layout);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        handler.removeCallbacksAndMessages(null);
    }

    class MyAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public Object getItem(int arg0) {
            return arg0;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            Holder mHolder;
            if (convertView == null) {
                mHolder = new Holder();
                convertView = View.inflate(Main_geren_send_fuwuActivity.this, R.layout.listview_item_layout, null);
                mHolder.place_text = (TextView) convertView.findViewById(R.id.place_text);
                convertView.setTag(mHolder);
            }
            mHolder = (Holder) convertView.getTag();
            mHolder.place_text.setText(list.get(position).getName());
            return convertView;
        }
    }

    class Holder {
        TextView place_text;
    }
}
